﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;

namespace SystemHelperLibrary.WPF.Converters
{
	public class SortDirectionConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value == null)
				return null;

			switch ((ListSortDirection)value)
			{
				case ListSortDirection.Ascending:
					return "Ascending";
				case ListSortDirection.Descending:
					return "Descending";
				default:
					return null;
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			switch ((string)value)
			{
				case "null":
					return null;
				case "Ascending":
					return ListSortDirection.Ascending;
				case "Descending":
					return ListSortDirection.Descending;
				default:
					break;
			}

			return null;
		}

		#endregion
	}
}
